﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class frmXemDonHang : Form
    {
        public frmXemDonHang()
        {
            InitializeComponent();
        }

        private void btXemDH_Click(object sender, EventArgs e)
        {
            DonHangBUS dhbus= new DonHangBUS();
            int soluong=0;
            string bien = " ";
            if (rdTatCa.Checked == true)
            {
                bien = "ALL";
                soluong = 0;
            }
            if (rdNhanVien.Checked == true)
            {
                bien = "NV";
                soluong = 0;
            }
            if (rdKhachHang.Checked == true)
            {
                bien = "KH";
                soluong = 0;
            }
            List<DonHangDTO> ds= dhbus.XemDonHang(bien,txtTimKiem.Text.ToString(), ref soluong);
           lbSoLuong.Text=  soluong.ToString();
           dgvDanhSach.Rows.Clear();
            for (int i = 0; i < ds.Count; i++)
            {
                TinhTrangBUS bustt = new TinhTrangBUS();
                string TinhTrang = bustt.TenTinhTrang( ds[i].MaTT);
                dgvDanhSach.Rows.Add(i + 1, ds[i].MaDH, ds[i].MaKH, ds[i].NVQL, ds[i].NgayDH,TinhTrang, ds[i].TongTien); 
            }
            
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void Hien()
        {
            if (rdKhachHang.Checked == true)
            {
                lbChon.Text = "Khách Hàng:";
                plTimKiem.Visible = true;
                plTimKiem.Show();
                dgvDanhSach.Rows.Clear();
            }
            if (rdNhanVien.Checked == true)
            {
                lbChon.Text = "Nhân Viên:";
                plTimKiem.Visible = true;
                plTimKiem.Show();
                dgvDanhSach.Rows.Clear();
            }

            if (rdTatCa.Checked == true)
            {
                plTimKiem.Visible = false;
                plTimKiem.Hide();
                dgvDanhSach.Rows.Clear();

            }
        }
        private void rdTatCa_CheckedChanged(object sender, EventArgs e)
        {
            Hien();
            lbSoLuong.Text = "0";
        }

        private void rdKhachHang_CheckedChanged(object sender, EventArgs e)
        {
            Hien();
            txtTimKiem.Text = "";
            lbSoLuong.Text = "0";
            LayMaKH();
        }

        private void rdNhanVien_CheckedChanged(object sender, EventArgs e)
        {
            Hien();
            txtTimKiem.Text = "";
            lbSoLuong.Text = "0";
            LayMaNV();
        }

        private void rdTinhTrang_CheckedChanged(object sender, EventArgs e)
        {
            Hien();
        }

        private void rdMonAn_CheckedChanged(object sender, EventArgs e)
        {
            Hien();
        }

        private void frmXemDonHang_Load(object sender, EventArgs e)
        {
            rdTatCa.Checked = true;
 
        }

        private void LayMaKH()
        {
            AutoCompleteStringCollection auto = new AutoCompleteStringCollection();
            List<string> lis = new List<string>();
            KhachHangBUS bus = new KhachHangBUS();
            lis = bus.LayMaKH();
            for (int i = 0; i < lis.Count; i++)
                auto.Add(lis[i]);
            txtTimKiem.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtTimKiem.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtTimKiem.AutoCompleteCustomSource = auto;

        }
        private void LayMaNV()
        {
            AutoCompleteStringCollection auto = new AutoCompleteStringCollection();
            List<string> lis = new List<string>();
            NhanVienBUS bus = new NhanVienBUS();
            lis = bus.LayMaNV();
            for (int i = 0; i < lis.Count; i++)
                auto.Add(lis[i]);
            txtTimKiem.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtTimKiem.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtTimKiem.AutoCompleteCustomSource = auto;
        }


    }
}
